<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys"%><%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Add New Project</title>

    <link rel="stylesheet" href="../css/at.css" type="text/css">

    <script language="JavaScript" src="../js/at.js"></script>
    <script language="JavaScript">
    function doSubmit(f)
    {
        /*if (!checkField(f.name, "Project name is empty", "isNotEmpty"))
            return false;

        trimAllTextFields(f);
        normalizeAllTextFields(f);*/

        return true;
    }
    </script>
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="project" />
    <jsp:param name="pageAction" value="projectadd" />
</jsp:include>

<at:form scope="session" action="/project/projectadd.do" method="post" onsubmit="return doSubmit(this)">

<input type="hidden" name="submitted" value="1" />

<input type="hidden" name="reload" value="0" />

<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff" width="770">
<tr>
    <td class="pagetitle">
        &nbsp;Add New Project
    </td>
</tr>
<tr>
    <td class="pagetitle">
        <at:errors />
        <at:messages id="message" message="true">
            <span class="successmsg"><bean:write name="message"/></span>
        </at:messages>
    </td>
</tr>
<tr>
    <td>
        <table cellspacing="0" cellpadding="3" align="left" valign="top" border="0" bgcolor="#ffffff">
        <tr>
            <td colspan="4" class="formcomment">
                <span class="formfieldtitlereq">*</span> Indicates a required field.
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="4" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Select Customer to Add Project for:
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="4" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td rowspan="1"><img height="1" width="30" src="../img/pixel.gif" /></td>
            <td class="formfieldtitlereq" align="right">
                *
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="customerId"><span class="errormsg">Customer:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="customerId">Customer:</logic:messagesNotPresent>
            </td>
            <td width="82%">
                <at:select property="customerId" onchange="document.forms[0].elements['reload'].value='1'; document.forms[0].submit();" maxlength="70">
                    <at:option value="0">-- please select one --</at:option>
                    <at:options collection="<%=Keys.CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name" />
                </at:select>
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="4" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Specify Project Details
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="4" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td rowspan="3"><img height="1" width="30" src="../img/pixel.gif" /></td>
            <td class="formfieldtitlereq" align="right">
                *
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="name"><span class="errormsg">Project Name:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="name">Project Name:</logic:messagesNotPresent>
            </td>
            <td>
                <html:text property="name" style="width: 470px" maxlength="255"  size="57"/>
            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereqtop" align="right">
                <logic:present name="selectedCustomer" scope="session">
                    <bean:define id="customer" name="selectedCustomer" scope="session" type="com.actimind.actitime.beans.CustomerBean" />
                    <logic:equal value="true" name="customer" property="billable">
                *
                    </logic:equal>
                    <logic:notEqual value="true" name="customer" property="billable">
                &nbsp;
                    </logic:notEqual>
                </logic:present>
                <logic:notPresent name="selectedCustomer" scope="session">
                &nbsp;
                </logic:notPresent>
            </td>
            <td class="formfieldtitletop">
                <logic:messagesPresent property="billable"><span class="errormsg">Billing Status:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="billable">Billing Status:</logic:messagesNotPresent>
            </td>
            <td class="formfieldtitletop">

            <logic:present name="selectedCustomer" scope="session">
                <logic:equal value="true" name="customer" property="billable">
                <table cellspacing="0" cellpadding="0" align="left" valign="top" border="0">
                <tr>
                    <td class="formfieldtitletop">
                        <html:radio property="billable" value="true" />
                    </td>
                    <td class="formfieldtitletop">
                        Billable, default billing type for project's tasks:
                        <at:select property="defaultBillingTypeId" maxlength="50" onchange="document.forms[0].elements['billable'][0].checked = true" >
                            <at:option value="0">-- please select one --</at:option>
                            <at:options collection="<%=Keys.TYPES_LIST_KEY%>" property="id" labelProperty="name" />
                        </at:select><br />
                        <span class="smallcomment">Select billing type that will be used as default when creating project's tasks.</span><br />
                    </td>
                </tr>
                <tr>
                    <td class="formfieldtitletop" style="vertical-align: middle">
                        <html:radio property="billable" value="false"/>
                    </td>
                    <td class="formfieldtitletop" style="vertical-align: middle">
                        Non-Billable
                    </td>
                </tr>
                </table>
                </logic:equal>

                <logic:notEqual value="true" name="customer" property="billable">
                <html:hidden property="billable" />
                <html:hidden property="defaultBillingTypeId" />
                Non-Billable
                </logic:notEqual>
            </logic:present>

            <logic:notPresent name="selectedCustomer" scope="session">
                <html:hidden property="billable" />
                <html:hidden property="defaultBillingTypeId" />
                Non-Billable
            </logic:notPresent>

            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereqtop">
                &nbsp;
            </td>
            <td class="formfieldtitletop" nowrap="1">
                <logic:messagesPresent property="description"><span class="errormsg">Project Description:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="description">Project Description:</logic:messagesNotPresent>
            </td>
            <td>
                <html:textarea property="description" style="width: 470px; height: 120px; " rows="7" cols="55" />
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="4" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Choose Project to Copy Tasks from:
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="1" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td class="formfieldtitlereqtop">&nbsp;</td>
            <td class="formfieldtitletop">
                <html:radio property="copyTasks" value="false" />
            </td>
            <td colspan="2" class="formfieldtitletop">
                Do not copy tasks from other projects, just register this project
            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereqtop">&nbsp;</td>
            <td class="formfieldtitletop">
                <html:radio property="copyTasks" value="true"/>
            </td>
            <td colspan="2" class="formfieldtitletop">
                Copy tasks from the following project:<br>
                <span class="smallcomment">The system will take names, billing types,
                and descriptions from the selected project's tasks and automatically
                add tasks with the same parameters to the newly registered project.
                <b>Note that deadlines will not be copied.</b></span><br/>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="formfieldtitlereqtop">&nbsp;</td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="copyCustomerId"><span class="errormsg">Customer:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="copyCustomerId">Customer:</logic:messagesNotPresent>
            </td>
            <td>
                <at:select property="copyCustomerId" childSelect="copyProjectId" firstChildText="-- please select one --" firstChildValue="0" maxlength="70" 
                        onchange="document.forms[0].elements['copyTasks'][1].checked = true; if(getVal(this)=='-1') {copyProjectId.options[0].text='-- please select a customer --';}">
                    <at:option value="-1">-- please select one --</at:option>
                    <at:options collection="<%=Keys.SRC_CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name" />
                </at:select>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="formfieldtitlereqtop">&nbsp;</td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="copyProjectId"><span class="errormsg">Project:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="copyProjectId">Project:</logic:messagesNotPresent>
            </td>
            <td>
                <at:select property="copyProjectId" parentSelect="copyCustomerId" firstChildText="-- please select a customer --" firstChildValue="0" maxlength="70" onchange="document.forms[0].elements['copyTasks'][1].checked = true">
                    <at:options collection="<%=Keys.SRC_PROJECTS_LIST_KEY%>" property="id" parentProperty="customerId" labelProperty="name" />
                </at:select>
            </td>
        </tr>
        </tr>
        <tr>
            <td colspan="4"><img height="10" width="1" src="../img/pixel.gif" /></td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td align="center" class="formbuttonpane">
        <input type="submit" value="Create Project" />
        <img height="1" width="100" src="../img/pixel.gif" />
        <input type="button" value="    Cancel    " onclick="if (confirm('Are you sure you want to cancel adding project?')) document.location.href='<html:rewrite href='projectlist.do'/>'" />
    </td>
</tr>
</table>

</at:form>

</body>
</html>
